<?php

namespace app\common\model;

use app\common\CommonResponse;
use think\Model;

class User extends Model
{
    protected $pk = 'id';
    protected $table = 'lcn_user';
    public function login($formUser){
        $user = $this::where("phone", $formUser['phone'])->find();
        if(!$user){
            return CommonResponse::error("用户不存在");
        }
        if(md5($formUser['password'])!=$user['password']){
            return CommonResponse::error("密码错误");
        }
        return CommonResponse::success("success",$user);
    }

    public function register($formUser){
        $checkRegister = $this::where("phone", $formUser['phone'])->find();
        if($checkRegister){
            return CommonResponse::error("当前号码已注册");
        }
        $formUser['password']=md5($formUser['password']);
        $formUser['state']=1;
        $saveUser = $this::save($formUser);
        if($saveUser){
            return CommonResponse::success("注册成功");
        }
        return CommonResponse::error("注册失败");

    }
    public function getPowerTeacher(){
       return $this->where("state",3)->select();
    }
}
